a07106c913b4c461e87a70f832fbefe0359b68c6,eventsourcing-core/src/test/java/com/eventsourcing/index/UniqueIndexTest.java,UniqueIndexTest,uniqueIndex,#,82
Before Change
// Add some indexes...
UniqueIndex index = onAttribute(Car.CAR_ID);
cars.addIndex(index);
cars.addIndex(HashIndex.onAttribute(Car.CAR_ID));
// Add some objects to the collection...
cars.add(new Car(1, "ford focus", "great condition, low mileage", Arrays.asList("spare tyre", "sunroof")));
After Change
// Add some indexes...
UniqueIndex index = onAttribute(Car.CAR_ID);
cars.addIndex(index);
HashIndex<Integer, Car> index1 = HashIndex.onAttribute(Car.CAR_ID);
cars.addIndex(index1);
index.clear(noQueryOptions());
index1.clear(noQueryOptions());
// Add some objects to the collection...
cars.add(new Car(1, "ford focus", "great condition, low mileage", Arrays.asList("spare tyre", "sunroof")));
cars.add(new Car(2, "ford taurus", "dirty and unreliable, flat tyre", Arrays.asList("spare tyre", "radio")));
cars.add(new Car(3, "honda civic", "has a flat tyre and high mileage", Arrays.asList("radio")));
Query<Car> query = equal(Car.CAR_ID, 2);
ResultSet<Car> rs = cars.retrieve(query);
assertEquals(rs.getRetrievalCost(), index.retrieve(query, noQueryOptions()).getRetrievalCost(),
"should prefer unique index over hash index");
assertEquals(rs.uniqueResult().carId, 2, "should retrieve car 2");
index.clear(noQueryOptions());
index1.clear(noQueryOptions());
}